// 表格列配置
export const options = [
  {
    label: "主图",
    prop: "primaryImage",
    width: "100",
    formatter: (row) => {
      return row.primaryImage
        ? `<img src="${row.primaryImage}" style="width: 50px; height: 50px;">`
        : "暂无图片";
    },
  },
  {
    label: "商品名称",
    prop: "title",
    width: "200",
  },
  {
    label: "库存",
    prop: "spuStockQuantity",
    width: "100",
  },
  {
    label: "推荐",
    prop: "isRecommend",
    width: "80",
    formatter: (row) => (row.isRecommend ? "是" : "否"),
  },
  {
    label: "排序",
    prop: "sort",
    width: "80",
  },
  {
    label: "销售价",
    prop: "salePrice",
    width: "100",
    formatter: (row) => `￥${row.salePrice?.toFixed(2) || "0.00"}`,
  },
  {
    label: "分类",
    prop: "cateId",
    width: "120",
  },
  {
    label: "品牌",
    prop: "brandId",
    width: "120",
  },
  {
    label: "更新时间",
    prop: "updateTime",
    width: "180",
    formatter: (row) =>
      row.updateTime ? new Date(row.updateTime).toLocaleString() : "-",
  },
];

// 表单校验规则
export const rules = {
  title: [{ required: true, message: "请输入商品名称", trigger: "blur" }],
  spuStockQuantity: [
    { required: true, message: "请输入库存数量", trigger: "blur" },
    { type: "number", message: "库存必须为数字", trigger: "blur" },
  ],
  sort: [
    { required: true, message: "请输入排序号", trigger: "blur" },
    { type: "number", message: "排序号必须为数字", trigger: "blur" },
  ],
  salePrice: [
    { required: true, message: "请输入销售价格", trigger: "blur" },
    { type: "number", message: "销售价格必须为数字", trigger: "blur" },
  ],
  cateId: [{ required: true, message: "请选择商品分类", trigger: "change" }],
  brandId: [{ required: true, message: "请选择商品品牌", trigger: "change" }],
};

// 表单默认值
export const defaultForm = {
  primaryImage: "",
  title: "",
  spuStockQuantity: 0,
  isRecommend: false,
  sort: 0,
  salePrice: 0,
  cateId: null,
  brandId: null,
  status: 0,
};

// 商品状态选项
export const statusOptions = [
  {
    value: 0,
    label: "下架",
  },
  {
    value: 1,
    label: "上架",
  },
];
